<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="id" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场站id" prop="changzhanid">
        <el-input
          v-model="queryParams.changzhanid"
          placeholder="请输入场站id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编号" prop="bianhao">
        <el-input
          v-model="queryParams.bianhao"
          placeholder="请输入编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名字" prop="mingzi">
        <el-input
          v-model="queryParams.mingzi"
          placeholder="请输入名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ruoyi-yuce:fengji:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ruoyi-yuce:fengji:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ruoyi-yuce:fengji:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ruoyi-yuce:fengji:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fengjiList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="场站id" align="center" prop="changzhanid" />
      <el-table-column label="编号" align="center" prop="bianhao" />
      <el-table-column label="名字" align="center" prop="mingzi" />
      <el-table-column label="风机厂家" align="center" prop="fjchangjia" />
      <el-table-column label="风机类型id" align="center" prop="fjtypeid" />
      <el-table-column label="风机类型" align="center" prop="fjleixing" />
      <el-table-column label="经度" align="center" prop="longtitude" />
      <el-table-column label="维度" align="center" prop="latitude" />
      <el-table-column label="海拔" align="center" prop="altitude" />
      <el-table-column label="检修标识" align="center" prop="jianxiuflag" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ruoyi-yuce:fengji:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ruoyi-yuce:fengji:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改风机对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="场站id" prop="changzhanid">
          <el-input v-model="form.changzhanid" placeholder="请输入场站id" />
        </el-form-item>
        <el-form-item label="编号" prop="bianhao">
          <el-input v-model="form.bianhao" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="名字" prop="mingzi">
          <el-input v-model="form.mingzi" placeholder="请输入名字" />
        </el-form-item>
        <el-form-item label="电压等级id" prop="dianyadengjiid">
          <el-input v-model="form.dianyadengjiid" placeholder="请输入电压等级id" />
        </el-form-item>
        <el-form-item label="FenQi" prop="fenqi">
          <el-input v-model="form.fenqi" placeholder="请输入FenQi" />
        </el-form-item>
        <el-form-item label="机电箱id" prop="jidianxianid">
          <el-input v-model="form.jidianxianid" placeholder="请输入机电箱id" />
        </el-form-item>
        <el-form-item label="容量" prop="capacity">
          <el-input v-model="form.capacity" placeholder="请输入容量" />
        </el-form-item>
        <el-form-item label="样板机标识" prop="yangbanjiflag">
          <el-input v-model="form.yangbanjiflag" placeholder="请输入样板机标识" />
        </el-form-item>
        <el-form-item label="风机厂家" prop="fjchangjia">
          <el-input v-model="form.fjchangjia" placeholder="请输入风机厂家" />
        </el-form-item>
        <el-form-item label="风机类型id" prop="fjtypeid">
          <el-input v-model="form.fjtypeid" placeholder="请输入风机类型id" />
        </el-form-item>
        <el-form-item label="风机类型" prop="fjleixing">
          <el-input v-model="form.fjleixing" placeholder="请输入风机类型" />
        </el-form-item>
        <el-form-item label="经度" prop="longtitude">
          <el-input v-model="form.longtitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="维度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入维度" />
        </el-form-item>
        <el-form-item label="海拔" prop="altitude">
          <el-input v-model="form.altitude" placeholder="请输入海拔" />
        </el-form-item>
        <el-form-item label="品牌标识" prop="brandflag">
          <el-input v-model="form.brandflag" placeholder="请输入品牌标识" />
        </el-form-item>
        <el-form-item label="RTUID" prop="rtuid">
          <el-input v-model="form.rtuid" placeholder="请输入RTUID" />
        </el-form-item>
        <el-form-item label="ShouLeiFlag" prop="shouleiflag">
          <el-input v-model="form.shouleiflag" placeholder="请输入ShouLeiFlag" />
        </el-form-item>
        <el-form-item label="检修标识" prop="jianxiuflag">
          <el-input v-model="form.jianxiuflag" placeholder="请输入检修标识" />
        </el-form-item>
        <el-form-item label="${comment}" prop="chargeperson">
          <el-input v-model="form.chargeperson" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="agcallowflag">
          <el-input v-model="form.agcallowflag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="shiyanflag">
          <el-input v-model="form.shiyanflag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="agcdnplmt">
          <el-input v-model="form.agcdnplmt" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="createdate">
          <el-date-picker clearable
            v-model="form.createdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="delflag">
          <el-input v-model="form.delflag" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="updatedate">
          <el-date-picker clearable
            v-model="form.updatedate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="updater">
          <el-input v-model="form.updater" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="xinghao">
          <el-input v-model="form.xinghao" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="tatong">
          <el-input v-model="form.tatong" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFengji, getFengji, delFengji, addFengji, updateFengji } from "@/api/ruoyi-yuce/fengji";

export default {
  name: "Fengji",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 风机表格数据
      fengjiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        changzhanid: null,
        bianhao: null,
        mingzi: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        changzhanid: [
          { required: true, message: "场站id不能为空", trigger: "blur" }
        ],
        bianhao: [
          { required: true, message: "编号不能为空", trigger: "blur" }
        ],
        mingzi: [
          { required: true, message: "名字不能为空", trigger: "blur" }
        ],
        dianyadengjiid: [
          { required: true, message: "电压等级id不能为空", trigger: "blur" }
        ],
        fenqi: [
          { required: true, message: "FenQi不能为空", trigger: "blur" }
        ],
        jidianxianid: [
          { required: true, message: "机电箱id不能为空", trigger: "blur" }
        ],
        capacity: [
          { required: true, message: "容量不能为空", trigger: "blur" }
        ],
        yangbanjiflag: [
          { required: true, message: "样板机标识不能为空", trigger: "blur" }
        ],
        fjchangjia: [
          { required: true, message: "风机厂家不能为空", trigger: "blur" }
        ],
        fjtypeid: [
          { required: true, message: "风机类型id不能为空", trigger: "blur" }
        ],
        fjleixing: [
          { required: true, message: "风机类型不能为空", trigger: "blur" }
        ],
        plctype: [
          { required: true, message: "PLCType不能为空", trigger: "change" }
        ],
        longtitude: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        latitude: [
          { required: true, message: "维度不能为空", trigger: "blur" }
        ],
        altitude: [
          { required: true, message: "海拔不能为空", trigger: "blur" }
        ],
        brandflag: [
          { required: true, message: "品牌标识不能为空", trigger: "blur" }
        ],
        rtuid: [
          { required: true, message: "RTUID不能为空", trigger: "blur" }
        ],
        shouleiflag: [
          { required: true, message: "ShouLeiFlag不能为空", trigger: "blur" }
        ],
        jianxiuflag: [
          { required: true, message: "检修标识不能为空", trigger: "blur" }
        ],
        chargeperson: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        agcallowflag: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        shiyanflag: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        agcdnplmt: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        delflag: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询风机列表 */
    getList() {
      this.loading = true;
      listFengji(this.queryParams).then(response => {
        this.fengjiList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        changzhanid: null,
        bianhao: null,
        mingzi: null,
        dianyadengjiid: null,
        fenqi: null,
        jidianxianid: null,
        capacity: null,
        yangbanjiflag: null,
        fjchangjia: null,
        fjtypeid: null,
        fjleixing: null,
        plctype: null,
        longtitude: null,
        latitude: null,
        altitude: null,
        brandflag: null,
        rtuid: null,
        shouleiflag: null,
        jianxiuflag: null,
        chargeperson: null,
        agcallowflag: null,
        shiyanflag: null,
        agcdnplmt: null,
        createdate: null,
        creator: null,
        delflag: null,
        updatedate: null,
        updater: null,
        xinghao: null,
        tatong: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加风机";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFengji(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改风机";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFengji(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFengji(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除风机编号为"' + ids + '"的数据项？').then(function() {
        return delFengji(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ruoyi-yuce/fengji/export', {
        ...this.queryParams
      }, `fengji_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
